package com.ruoyi.ob.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ob.domain.PurchaseOrderDetail;
import com.ruoyi.ob.service.IPurchaseOrderDetailService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 采购订单明细Controller
 * 
 * @author ruoyi
 * @date 2025-06-18
 */
@Controller
@RequestMapping("/ob/detail")
public class PurchaseOrderDetailController extends BaseController
{
    private String prefix = "ob/detail";

    @Autowired
    private IPurchaseOrderDetailService purchaseOrderDetailService;

    @RequiresPermissions("ob:detail:view")
    @GetMapping()
    public String detail()
    {
        return prefix + "/detail";
    }

    /**
     * 查询采购订单明细列表
     */
    @RequiresPermissions("ob:detail:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PurchaseOrderDetail purchaseOrderDetail)
    {
        startPage();
        List<PurchaseOrderDetail> list = purchaseOrderDetailService.selectPurchaseOrderDetailList(purchaseOrderDetail);
        return getDataTable(list);
    }

    /**
     * 导出采购订单明细列表
     */
    @RequiresPermissions("ob:detail:export")
    @Log(title = "采购订单明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PurchaseOrderDetail purchaseOrderDetail)
    {
        List<PurchaseOrderDetail> list = purchaseOrderDetailService.selectPurchaseOrderDetailList(purchaseOrderDetail);
        ExcelUtil<PurchaseOrderDetail> util = new ExcelUtil<PurchaseOrderDetail>(PurchaseOrderDetail.class);
        return util.exportExcel(list, "采购订单明细数据");
    }

    /**
     * 新增采购订单明细
     */
    @RequiresPermissions("ob:detail:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存采购订单明细
     */
    @RequiresPermissions("ob:detail:add")
    @Log(title = "采购订单明细", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PurchaseOrderDetail purchaseOrderDetail)
    {
        return toAjax(purchaseOrderDetailService.insertPurchaseOrderDetail(purchaseOrderDetail));
    }

    /**
     * 修改采购订单明细
     */
    @RequiresPermissions("ob:detail:edit")
    @GetMapping("/edit/{detailId}")
    public String edit(@PathVariable("detailId") String detailId, ModelMap mmap)
    {
        PurchaseOrderDetail purchaseOrderDetail = purchaseOrderDetailService.selectPurchaseOrderDetailByDetailId(detailId);
        mmap.put("purchaseOrderDetail", purchaseOrderDetail);
        return prefix + "/edit";
    }

    /**
     * 修改保存采购订单明细
     */
    @RequiresPermissions("ob:detail:edit")
    @Log(title = "采购订单明细", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PurchaseOrderDetail purchaseOrderDetail)
    {
        return toAjax(purchaseOrderDetailService.updatePurchaseOrderDetail(purchaseOrderDetail));
    }

    /**
     * 删除采购订单明细
     */
    @RequiresPermissions("ob:detail:remove")
    @Log(title = "采购订单明细", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(purchaseOrderDetailService.deletePurchaseOrderDetailByDetailIds(ids));
    }

}
